﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ping9719.DeviceCommunication.Common.Helpers
{
    public class WordHelp
    {
        /// <summary>
        /// 指定类型占用的数量
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>0为无法判断</returns>
        public static int OccupyNum<T>()
        {
            var tType = typeof(T);
            if (tType == typeof(bool) || tType == typeof(byte) || tType == typeof(short) || tType == typeof(ushort))
                return 1;
            else if (tType == typeof(int) || tType == typeof(uint) || tType == typeof(float))
                return 2;
            else if (tType == typeof(double) || tType == typeof(long) || tType == typeof(ulong))
                return 4;
            else
                return 0;
        }
    }
}
